﻿var winState = "0";
var GName = "";
Ext.onReady(function () {
    yeardata = new Ext.data.JsonStore({
        url: Ext.getClassUrl('RecyclingView', 'GetYearTime'),
        root: 'ResponseObject',
        fields: ['yearid', 'yeartext'],
        listeners: {
            beforeload: function (st, op) {
                var re = new JsonRequest();
                re.category = CATEGORY.READONLY;
                st.baseParams = re;
                st.proxy.conn.jsonData = re;
            }
        }
    });
    yeardata.load();
    //数据列表
    var lmsstore = new Ext.data.JsonStore({
        url: Ext.getClassUrl('RecyclingView', 'GetFy'),
        root: 'ResponseObject',
        fields: ['材料名称', 'a22', '入库数量', '使用数量'],
        listeners: {
            beforeload: function (st, op) {
                var re = new JsonRequest();
                re.category = CATEGORY.READONLY;
                re.params.year = Ext.getCmp("year").getValue();
                re.params.month = Ext.getCmp("month").getValue();
                re.params.groupname = GName;
                st.baseParams = re;
                st.proxy.conn.jsonData = re;
            },
            load: function (st) {
                Ext.getCmp('chart').bindStore(st);
            }
        }
    });

    var lmsstore1 = new Ext.data.JsonStore({
        url: Ext.getClassUrl('RecyclingView', 'GetFy'),
        root: 'ResponseObject',
        fields: ['材料名称', 'a22', '入库数量', '使用数量'],
        listeners: {
            beforeload: function (st, op) {
                var re = new JsonRequest();
                re.category = CATEGORY.READONLY;
                re.params.year = Ext.getCmp("year").getValue();
                re.params.month = Ext.getCmp("month").getValue();
                re.params.groupname = GName;
                st.baseParams = re;
                st.proxy.conn.jsonData = re;
            },
            load: function (st) {
                Ext.getCmp('chart').bindStore(st);
            }
        }
    });

    function NumFormat(s, m) {
        if (s < 0) m.css = 'redNum';
        //if (s == 0) return '';
        return Ext.util.Format.number(s, '0.00');
    }
    var lmsdatagrid = new Ext.grid.GridPanel({
        autoscroll: true,
        bodyStyle: 'padding:2px',
        border: false,
        loadMask: true, //加载
        columns: [
           { id: '材料名称', header: '材料名称', width: 100, dataIndex: '材料名称', sortable: true },
           { header: '队组名称', width: 100, dataIndex: 'a22', sortable: true },
           { header: '入库数量', width: 100, dataIndex: '入库数量', sortable: true, renderer: NumFormat },
           { header: '使用数量', width: 100, dataIndex: '使用数量', sortable: true, renderer: NumFormat }
        ],
        store: lmsstore,
        listeners: {
            celldblclick: function (grid, rindex) {
                //window.open('ZL_ReportMore.aspx');
            }
        }
    });


    var lmsdatagrid1 = new Ext.grid.GridPanel({
        autoscroll: true,
        bodyStyle: 'padding:2px',
        border: false,
        loadMask: true, //加载
        columns: [
           { id: '材料名称', header: '材料名称', width: 100, dataIndex: '材料名称', sortable: true },
           { id: '队组名称', header: '队组名称', width: 100, dataIndex: 'a22', sortable: true },
           { id: '入库数量', header: '入库数量', width: 100, dataIndex: '入库数量', sortable: true, renderer: NumFormat },
           { id: '使用数量', header: '使用数量', width: 100, dataIndex: '使用数量', sortable: true, renderer: NumFormat }
        ],
        store: lmsstore1,
        listeners: {
            celldblclick: function (grid, rindex) {
                window.open('ZL_ReportMore.aspx');
            }
        }
    });
    //布局
    new Ext.Viewport({
        layout: 'border',
        items: [{
            region: 'center',
            layout: 'border',
            border: false,
            title: '掘进队复用情况报表',
            iconCls: 'ReportTitle-icon',
            tbar: ['日期：', { xtype: 'combo', width: 100, id: 'year',
                typeAhead: true,
                triggerAction: 'all',
                lazyRender: true,
                mode: 'local',
                store: yeardata,
                valueField: 'yearid',
                displayField: 'yeartext'

            }, '年', { xtype: 'combo', width: 70, id: 'month',
                typeAhead: true,
                triggerAction: 'all',
                lazyRender: true,
                mode: 'local',
                store: new Ext.data.ArrayStore({
                    id: 0,
                    fields: [
                            'monthid',
                            'monthtext'
                        ],
                    data: [['01', '01'], ['02', '02'], ['03', '03'], ['04', '04'], ['05', '05'], ['06', '06'], ['07', '07'], ['08', '08'], ['09', '09'], ['10', '10'], ['11', '11'], ['12', '12']]
                }),
                valueField: 'monthid',
                displayField: 'monthtext'
            }, '月', { xtype: 'button', text: '查询', iconCls: 'search-icon', handler: function () {
                //                if (Ext.getCmp("tabdata").activeTab.title == "采一队") {
                //                    GName = "采一队";
                //                    lmsstore.load();
                //                }
                //                if (Ext.getCmp("tabdata").activeTab.title == "采二队") {
                //                    GName = "采二队";
                //                    lmsstore1.load();
                //                }
                active(Ext.getCmp("tabdata").activeTab, lmsstore, lmsstore1);
            }
            }, '->', { xtype: 'button', text: '返回', height: 20, width: 50, iconCls: 'page-back-icon', handler: function () {
                window.history.back(-1);
            }
            }],
            items: [{
                region: 'west',
                title: '数据报表',
                iconCls: 'DataList-icon',
                style: 'padding:2px',
                collapsible: true,
                width: 460,
                split: true,
                id: 'DataList',
                layout: 'fit',
                items: new Ext.TabPanel({
                    activeTab: 0,
                    id: 'tabdata',
                    style: 'padding:1px',
                    items: [{
                        title: '掘一队',
                        layout: 'fit',
                        items: lmsdatagrid
                    }, {
                        title: '掘二队',
                        layout: 'fit',
                        items: lmsdatagrid1
                    }],
                    listeners: {
                        tabchange: function (e, k) {
                            active(Ext.getCmp("tabdata").activeTab, lmsstore, lmsstore1);
                        }
                    }
                })
            }, {
                region: 'center',
                split: true,
                layout: 'fit',
                border: false,
                split: true,
                id: 'ImgCount',
                items: {
                    id: 'chart',
                    xtype: 'columnchart',
                    //store: lmsstore,
                    xField: '材料名称',
                    yAxis: new Ext.chart.NumericAxis({
                        labelRenderer: Ext.util.Format.numberRenderer('0,0')
                    }),
                    chartStyle: {
                        padding: 10,
                        animationEnabled: true,
                        legend: {
                            display: 'right',
                            padding: 2,
                            font: {
                                family: 'Tahoma',
                                size: 11
                            }
                        },
                        font: {
                            name: 'Tahoma',
                            color: 0x444444,
                            size: 11
                        },
                        xAxis: {
                            color: 0x69aBc8,
                            majorTicks: { color: 0x69aBc8, length: 4 },
                            minorTicks: { color: 0x69aBc8, length: 2 },
                            majorGridLines: { size: 1, color: 0xeeeeee },
                            labelRotation: -90
                        },
                        yAxis: {
                            zeroGridLine: {
                                size: 2,
                                color: 0xff0000
                            },
                            color: 0x69aBc8,
                            majorTicks: { color: 0x69aBc8, length: 4 },
                            minorTicks: { color: 0x69aBc8, length: 2 },
                            majorGridLines: { size: 1, color: 0xdfe8f6 }
                        }
                    },
                    series: [{
                        type: 'column',
                        displayName: '入库数量',
                        yField: '入库数量'
                    }, {
                        type: 'column',
                        displayName: '使用数量',
                        yField: '使用数量'
                    }]
                }
            }]
        }],
        listeners: {
            render: function () {
                Ext.getCmp("year").setValue(YearT);
                Ext.getCmp("month").setValue(MonthT);
                active(Ext.getCmp("tabdata").activeTab, lmsstore, lmsstore1);
            }
        }
    })
});

var active = function (title1, lmsstore, lmsstore1) {
    if (title1.title == "掘一队") {
        GName = "掘一队";
        lmsstore.load();
    }
    if (title1.title == "掘二队") {
        GName = "掘二队";
        lmsstore1.load();
    }
}